package com.fr.report;

import com.fr.base.FCloneable;
import com.fr.base.Inter;
import com.fr.base.XMLable;
import com.fr.base.background.Background;
import com.fr.base.background.ColorBackground;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.io.xml.SynchronizedNameWidget;
import com.fr.report.parameter.CustomParameterUI;
import com.fr.report.parameter.Parameter;
import com.fr.report.parameter.ParameterProcessor;
import com.fr.report.parameter.ParameterUI;
import com.fr.report.web.ui.FieldEditor;
import com.fr.report.web.ui.Widget;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class ReportParameterAttr
  implements XMLable
{
  public static final int POPUP = 0;
  public static final int EMBED = 1;
  private boolean delayPlaying = true;
  private boolean showWindow = false;
  private int windowPosition = 1;
  private static final int LEFTPOSITION = 0;
  private static final int CENTERPOSITION = 1;
  private static final int RIGHTPOSITION = 2;
  private int align = 1;
  private Background background = ColorBackground.getInstance(new Color(238, 238, 238));
  private ParameterUI parameterUI = null;
  private ParameterProcessor parameterProcessor = null;
  private List parameters = new ArrayList();
  private String parameterWindowTitle = Inter.getLocText("Parameter");

  public String getParameterWindowTitle()
  {
    return this.parameterWindowTitle;
  }

  public void setParameterWindowTitle(String paramString)
  {
    this.parameterWindowTitle = paramString;
  }

  public boolean isShowWindow()
  {
    return this.showWindow;
  }

  public void setShowWindow(boolean paramBoolean)
  {
    this.showWindow = paramBoolean;
  }

  public boolean isDelayPlaying()
  {
    return this.delayPlaying;
  }

  public void setDelayPlaying(boolean paramBoolean)
  {
    this.delayPlaying = paramBoolean;
  }

  public int getWindowPosition()
  {
    return this.windowPosition;
  }

  public void setWindowPosition(int paramInt)
  {
    this.windowPosition = paramInt;
  }

  public void setAlign(int paramInt)
  {
    this.align = paramInt;
  }

  public int getAlign()
  {
    return this.align;
  }

  public ParameterUI getParameterUI()
  {
    return this.parameterUI;
  }

  public void setParameterUI(ParameterUI paramParameterUI)
  {
    this.parameterUI = paramParameterUI;
  }

  public ParameterProcessor getParameterProcessor()
  {
    return this.parameterProcessor;
  }

  public void setParameterProcessor(ParameterProcessor paramParameterProcessor)
  {
    this.parameterProcessor = paramParameterProcessor;
  }

  public void addParameter(Parameter paramParameter)
  {
    this.parameters.add(paramParameter);
  }

  public void clearParameters()
  {
    this.parameters.clear();
  }

  public void clearParameter(Parameter paramParameter)
  {
    this.parameters.remove(paramParameter);
  }

  public Parameter[] getParameters()
  {
    return ((Parameter[])this.parameters.toArray(new Parameter[this.parameters.size()]));
  }

  public Background getBackground()
  {
    return this.background;
  }

  public void setBackground(Background paramBackground)
  {
    this.background = paramBackground;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    String str1 = null;
    if (paramXMLableReader.isChildNode())
    {
      String str2 = paramXMLableReader.getTagName();
      if ("Attributes".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("showWindow")) != null)
          setShowWindow(Boolean.valueOf(str1).booleanValue());
        if ((str1 = paramXMLableReader.getAttr("delayPlaying")) != null)
          setDelayPlaying(Boolean.valueOf(str1).booleanValue());
        if ((str1 = paramXMLableReader.getAttr("windowPosition")) != null)
          setWindowPosition(Integer.parseInt(str1));
        if ((str1 = paramXMLableReader.getAttr("align")) != null)
          setAlign(Integer.parseInt(str1));
        label462: if ((str1 = paramXMLableReader.getAttr("userDefineWindow")) != null)
          if (Boolean.valueOf(str1).booleanValue())
            this.parameterUI = new CustomParameterUI();
          else
            this.parameterUI = CustomParameterUI.createDefaultParameterUI();
      }
      else if (("ParameterInterface".equals(str2)) || ("ParameterUI".equals(str2)))
      {
        if (ComparatorUtils.equals(paramXMLableReader.getAttr("class"), "com.fr.report.parameter.DefaultParameterInterface"))
          setShowWindow(false);
        else
          setParameterUI(ReportXMLUtils.readParameterUI(paramXMLableReader));
      }
      else if ("PP".equals(str2))
      {
        this.parameterProcessor = ReportXMLUtils.readParameterProcessor(paramXMLableReader);
      }
      else if ("PWTitle".equals(str2))
      {
        setParameterWindowTitle(paramXMLableReader.getElementValue());
      }
      else if ("Parameter".equals(str2))
      {
        this.parameters.add(ReportXMLUtils.readParameter(paramXMLableReader));
      }
      else if ("WorkSheet".equals(str2))
      {
        ParameterReport localParameterReport = new ParameterReport();
        paramXMLableReader.readXMLObject(localParameterReport);
        Iterator localIterator = localParameterReport.cellIterator();
        while (true)
        {
          CellElement localCellElement;
          do
            while (true)
            {
              while (true)
              {
                if (!(localIterator.hasNext()))
                  break label462;
                localCellElement = (CellElement)localIterator.next();
                if (!(localCellElement.getValue() instanceof Parameter))
                  break;
                localObject = (Parameter)localCellElement.getValue();
                localCellElement.setValue(((Parameter)localObject).getValue());
              }
              if (!(localCellElement.getValue() instanceof FieldEditor))
                break;
              Object localObject = SynchronizedNameWidget.getDefaultValue(((FieldEditor)localCellElement.getValue()).getFieldName());
              localCellElement.setWidget((Widget)localCellElement.getValue());
              localCellElement.setValue(localObject);
            }
          while (!(localCellElement.getValue() instanceof Widget));
          localCellElement.setWidget((Widget)localCellElement.getValue());
          localCellElement.setValue(null);
        }
        if ((localParameterReport != null) && (getParameterUI() instanceof CustomParameterUI))
          setParameterUI(new CustomParameterUI(localParameterReport));
      }
      else if ("Parameters".equals(str2))
      {
        this.parameters.addAll(Arrays.asList(ReportXMLUtils.readParameters(paramXMLableReader)));
      }
      else if ("Background".equals(str2))
      {
        setBackground(BaseXMLUtils.readBackground(paramXMLableReader));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Attributes").attr("showWindow", this.showWindow).attr("delayPlaying", this.delayPlaying).attr("windowPosition", this.windowPosition).attr("align", this.align).end();
    paramXMLPrintWriter.startTAG("PWTitle").textNode(getParameterWindowTitle()).end();
    ReportXMLUtils.writeXMLable(paramXMLPrintWriter, this.parameterUI, "ParameterUI");
    int i = 0;
    int j = this.parameters.size();
    while (i < j)
    {
      ReportXMLUtils.writeParameter(paramXMLPrintWriter, (Parameter)this.parameters.get(i));
      ++i;
    }
    if (this.parameterProcessor != null)
      ReportXMLUtils.writeParameterProcessor(paramXMLPrintWriter, this.parameterProcessor);
    if (!(ColorBackground.getInstance(new Color(238, 238, 238)).equals(this.background)))
      BaseXMLUtils.writeBackground(paramXMLPrintWriter, this.background);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ReportParameterAttr localReportParameterAttr = (ReportParameterAttr)super.clone();
    if (this.parameterUI != null)
      localReportParameterAttr.parameterUI = ((ParameterUI)this.parameterUI.clone());
    if (this.parameterProcessor != null)
      localReportParameterAttr.parameterProcessor = ((ParameterProcessor)this.parameterProcessor.clone());
    localReportParameterAttr.parameters = new ArrayList();
    int i = 0;
    int j = this.parameters.size();
    while (i < j)
    {
      localReportParameterAttr.parameters.add(((Parameter)this.parameters.get(i)).clone());
      ++i;
    }
    return localReportParameterAttr;
  }
}